package com.cadre.system;

import com.alibaba.fastjson.JSONArray;

import java.text.MessageFormat;
import java.util.Map;

/* loaded from: NameStringBuild.class */
public class NameStringBuild extends SQLStringBuild {
    String sqlstring = "a0101 like ''%{0}%'' or a0188 like ''%{1}%'' or a0191 like ''%{2}%''";

    public String builder_bak(Map<String, Object> map) {
        StringBuilder sqlbuilder = new StringBuilder();
        JSONArray valuestring = (JSONArray) map.get("valueString");
        for (int i = 0; i < valuestring.size(); i++) {
            if (i > 0) {
                sqlbuilder.append(" or ");
            }
            String value = valuestring.get(i).toString();
            sqlbuilder.append(MessageFormat.format(this.sqlstring, value, value, value));
        }
        return sqlbuilder.toString();
    }

    @Override // com.tdqy.cadre.modular.profess.common.SQLStringBuild
    public String builder(Map<String, Object> map) {
        StringBuilder sqlbuilder = new StringBuilder();
        JSONArray valuestring = (JSONArray) map.get("valueString");
        if (valuestring.size() == 1) {
            sqlbuilder.append(" a0101 like '%").append(valuestring.get(0)).append("%'");
            return sqlbuilder.toString();
        }
        for (int i = 0; i < valuestring.size(); i++) {
            if (i == 0) {
                sqlbuilder.append("a0101 like '%").append(valuestring.get(i)).append("%'");
            } else {
                sqlbuilder.append(" or a0101 like '%").append(valuestring.get(i)).append("%'");
            }
        }
        return sqlbuilder.toString();
    }

    public String builder_back(Map<String, Object> map) {
        StringBuilder sqlbuilder = new StringBuilder();
        JSONArray valuestring = (JSONArray) map.get("valueString");
        if (valuestring.size() == 1) {
            sqlbuilder.append(" a0101 like '%").append(valuestring.get(0)).append("%' or a0177b like '%").append(valuestring.get(0)).append("%'");
            return sqlbuilder.toString();
        }
        String a0101 = "";
        String a0177b = "";
        for (int i = 0; i < valuestring.size(); i++) {
            if (i == 0) {
                a0101 = "a0101 like '%" + valuestring.get(i) + "%'";
                a0177b = "a0177b like '%" + valuestring.get(i) + "%'";
            } else {
                a0101 = a0101 + " or a0101 like '%" + valuestring.get(i) + "%'";
                a0177b = a0177b + " or a0177b like '%" + valuestring.get(i) + "%'";
            }
        }
        return sqlbuilder.append("(").append(a0101).append(")").append(" and ").append("(").append(a0177b).append(")").toString();
    }

    public String builder_bac(Map<String, Object> map) {
        StringBuilder sqlbuilder = new StringBuilder("select personid from d_persontag d where ");
        String resume = "select DISTINCT(personid) from a19 where ";
        sqlbuilder.append("d.tagid = ").append(map.get("tagId").toString()).append(" and (");
        JSONArray valuestring = (JSONArray) map.get("valueString");
        if (valuestring.size() == 1) {
            sqlbuilder.append(" d.valuestring like '%").append(valuestring.get(0)).append("%')");
            sqlbuilder.append(" union ");
            sqlbuilder.append(resume).append("a1955 like '%" + valuestring.get(0) + "%'");
            sqlbuilder.append(" union ").append("select DISTINCT(personid) from a19b where ").append("a1955 like '%" + valuestring.get(0) + "%'");
            return sqlbuilder.toString();
        }
        for (int i = 0; i < valuestring.size(); i++) {
            if (i == 0) {
                sqlbuilder.append("d.valuestring like '%").append(valuestring.get(i)).append("%'");
                resume = resume + "a1955 like '%" + valuestring.get(i) + "%'";
            } else {
                sqlbuilder.append(" or d.valuestring like '%").append(valuestring.get(i)).append("%'");
                resume = resume + " or a1955 like '%" + valuestring.get(i) + "%'";
            }
        }
        return sqlbuilder.append(") intersect ").append(resume).append(" intersect ").append(resume.replace(" a19 ", " a19b ")).toString();
    }
}
